package com.supor.aiot.mine.ui.adapter;

import android.view.View;

import com.android.baseconfig.common.views.DividerView;
import com.android.baseconfig.recyclerview.adapter.BaseByViewHolder;
import com.android.baseconfig.recyclerview.adapter.BaseRecyclerAdapter;
import com.supor.aiot.common.app.Constants;
import com.supor.aiot.mine.R;
import com.supor.aiot.mine.bean.Dictionary;
import com.supor.aiot.mine.bean.WishBean;

import java.util.ArrayList;
import java.util.List;

import androidx.constraintlayout.widget.ConstraintLayout;

/**
 * ---------------------------------------------------------------- <br>
 * Copyright (C) 2014-2020, by het, Shenzhen, All rights reserved.  <br>
 * ---------------------------------------------------------------- <br>
 * <p>
 * 描述: DeviceAdapter <br>
 * 作者: lei <br>
 * 日期: 2021/7/16 <br>
 */
public class WishAdapter extends BaseRecyclerAdapter<WishBean> {

    List<Dictionary> dictionaryList = new ArrayList<>();

    public WishAdapter() {
        super(R.layout.item_wish);
    }

    public WishAdapter(List<WishBean> dataList) {
        super(R.layout.item_wish, dataList);
    }

    public void setDictionaryList(List<Dictionary> dictionaryList) {
        this.dictionaryList = dictionaryList;
    }

    @Override
    protected void bindView(BaseByViewHolder<WishBean> holder, WishBean data, int position) {
        DividerView dividerView = holder.itemView.findViewById(R.id.dv_line);
        ConstraintLayout.LayoutParams lp = (ConstraintLayout.LayoutParams) dividerView.getLayoutParams();
        if (position == 0) {
            lp.setMargins(lp.leftMargin,
                    holder.itemView.getResources().getDimensionPixelSize(R.dimen.dp_11),
                    lp.rightMargin, lp.bottomMargin);
            dividerView.setLayoutParams(lp);
        } else {
            lp.setMargins(lp.leftMargin, lp.topMargin, lp.rightMargin, lp.bottomMargin);
            dividerView.setLayoutParams(lp);
        }
        if (Constants.Type.CHEF_MACHINE.equalsIgnoreCase(data.modelId)) {
            holder.setImageResource(R.id.iv_device, R.mipmap.ic_device_chief_machine);
        } else if (Constants.Type.AUTO_RICE_COOKER.equalsIgnoreCase(data.modelId)) {
            holder.setImageResource(R.id.iv_device, R.mipmap.ic_device_auto_rice_cooker);
        } else if (Constants.Type.AIR_FRYER.equalsIgnoreCase(data.modelId)) {
            holder.setImageResource(R.id.iv_device, R.mipmap.ic_device_air_fryer);
        } else if (Constants.Type.HEALTH_POT.equalsIgnoreCase(data.modelId)) {
            holder.setImageResource(R.id.iv_device, R.mipmap.ic_device_health_pot);
        } else if (Constants.Type.INFANT_DEVICE.equalsIgnoreCase(data.modelId)) {
            holder.setImageResource(R.id.iv_device, R.mipmap.ic_device_infant);
        }
        holder.setText(R.id.tv_time, data.createTime);
        holder.setText(R.id.tv_name, data.wishName);
        holder.setText(R.id.tv_dec_value, data.wishDescription);
        StringBuilder sb = new StringBuilder();
        String[] array = data.tastes.split(",");
        for (String s : array) {
            for (Dictionary dictionary : dictionaryList) {
                if (s.equalsIgnoreCase(dictionary.dictionaryBean.getSysCodeSub())) {
                    sb.append(dictionary.dictionaryBean.getCnName());
                    sb.append("；");
                }
            }
        }
        if (sb.length() != 0) {
            sb.delete(sb.length() - 1, sb.length());
        }
        holder.setText(R.id.tv_taste_value, sb);
        holder.setText(R.id.tv_notify_value,
                data.isNotified == 1 ? holder.itemView.getResources().getString(R.string.open) :
                        holder.itemView.getResources().getString(R.string.close));
        // if (TextUtils.isEmpty(data.recipeId)) {
            // holder.setVisible(R.id.cl_recipe, false);
            holder.itemView.findViewById(R.id.cl_recipe).setVisibility(View.GONE);
        // } else {
        //     holder.setVisible(R.id.cl_recipe, true);
        //     holder.setText(R.id.tv_recipe_name, data.recipeName);
        //     BitmapUtil.loadUrl(holder.itemView.getContext(), data.recipeUrl,
        //             holder.itemView.findViewById(R.id.iv_icon));
        //     if (data.isSatisfied) {
        //         BitmapUtil.loadLocal(R.mipmap.ic_satisfy, holder.itemView.findViewById(R.id.iv_satisfy), BitmapUtil.options1);
        //         holder.setText(R.id.tv_satisfy_tip,
        //                 holder.itemView.getResources().getString(R.string.satisfy));
        //     } else {
        //         BitmapUtil.loadLocal(R.mipmap.ic_satisfy_off, holder.itemView.findViewById(R.id.iv_satisfy), BitmapUtil.options1);
        //         holder.setText(R.id.tv_satisfy_tip,
        //                 holder.itemView.getResources().getString(R.string.unsatisfy));
        //     }
        //
        // }
    }
}
